<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Git 笔记 | Aikikoの小窝</title><meta name="keywords" content="Git"><meta name="author" content="AikikoXHJ"><meta name="copyright" content="AikikoXHJ"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="这篇笔记是我学习廖雪峰大佬写的Git入门指南时候做的笔记，基本上就是将文章中使用到的 Git 指令记下来，包括了用法和拓展的说明。如果有错误的地方，还请指出，谢谢！！！ 简单介绍  Git 是分布式版本控制系统  执行提交时，系统会要求输入提交信息。    创建一个本地仓库及基本操作 创建一个版本库 12345$ mkdir 库名 #创建库$ cd 库名 #进入库$ pwd #打印出当前库的位置$">
<meta property="og:type" content="article">
<meta property="og:title" content="Git 笔记">
<meta property="og:url" content="http://example.com/2021/06/06/GitMarkdown/index.html">
<meta property="og:site_name" content="Aikikoの小窝">
<meta property="og:description" content="这篇笔记是我学习廖雪峰大佬写的Git入门指南时候做的笔记，基本上就是将文章中使用到的 Git 指令记下来，包括了用法和拓展的说明。如果有错误的地方，还请指出，谢谢！！！ 简单介绍  Git 是分布式版本控制系统  执行提交时，系统会要求输入提交信息。    创建一个本地仓库及基本操作 创建一个版本库 12345$ mkdir 库名 #创建库$ cd 库名 #进入库$ pwd #打印出当前库的位置$">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://cdn.jsdelivr.net/gh/AikikoXHJ/cloudimg/img/background.jpg">
<meta property="article:published_time" content="2021-06-05T16:00:00.000Z">
<meta property="article:modified_time" content="2021-06-08T15:53:31.671Z">
<meta property="article:author" content="AikikoXHJ">
<meta property="article:tag" content="Git">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://cdn.jsdelivr.net/gh/AikikoXHJ/cloudimg/img/background.jpg"><link rel="shortcut icon" href="https://cdn.jsdelivr.net/gh/AikikoXHJ/cloudimg/img/XHJ.jpg"><link rel="canonical" href="http://example.com/2021/06/06/GitMarkdown/"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/',
  algolia: undefined,
  localSearch: undefined,
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '天',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    jQuery: 'https://cdn.jsdelivr.net/npm/jquery@latest/dist/jquery.min.js',
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/js/jquery.justifiedGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/css/justifiedGallery.min.css'
    },
    fancybox: {
      js: 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.js',
      css: 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isanchor: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: 'Git 笔记',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2021-06-08 23:53:31'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    })(window)</script><link rel="stylesheet" href="/css/custom.css"  media="defer" onload="this.media='all'"><meta name="generator" content="Hexo 5.4.0"></head><body><div id="loading-box"><div class="loading-left-bg"></div><div class="loading-right-bg"></div><div class="spinner-box"><div class="configure-border-1"><div class="configure-core"></div></div><div class="configure-border-2"><div class="configure-core"></div></div><div class="loading-word">加载中...</div></div></div><z id="web_bg"></z><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="author-avatar"><img class="avatar-img" src="https://cdn.jsdelivr.net/gh/AikikoXHJ/cloudimg/img/XHJ.jpg" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="site-data"><div class="data-item is-center"><div class="data-item-link"><a href="/archives/"><div class="headline">文章</div><div class="length-num">2</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/tags/"><div class="headline">标签</div><div class="length-num">2</div></a></div></div></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> 清单</span><i class="fas fa-chevron-down expand"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/music/"><i class="fa-fw fas fa-music"></i><span> 音乐</span></a></li><li><a class="site-page child" href="/Gallery/"><i class="fa-fw fas fa-images"></i><span> 照片</span></a></li><li><a class="site-page child" href="/movies/"><i class="fa-fw fas fa-video"></i><span> 电影</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('https://cdn.jsdelivr.net/gh/AikikoXHJ/cloudimg/img/background.jpg')"><nav id="nav"><span id="blog_name"><a id="site-name" href="/">Aikikoの小窝</a></span><div id="menus"><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> 清单</span><i class="fas fa-chevron-down expand"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/music/"><i class="fa-fw fas fa-music"></i><span> 音乐</span></a></li><li><a class="site-page child" href="/Gallery/"><i class="fa-fw fas fa-images"></i><span> 照片</span></a></li><li><a class="site-page child" href="/movies/"><i class="fa-fw fas fa-video"></i><span> 电影</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">Git 笔记</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2021-06-05T16:00:00.000Z" title="发表于 2021-06-06 00:00:00">2021-06-06</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2021-06-08T15:53:31.671Z" title="更新于 2021-06-08 23:53:31">2021-06-08</time></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="Git 笔记"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><p>这篇笔记是我学习廖雪峰大佬写的Git入门指南时候做的笔记，基本上就是将文章中使用到的 Git 指令记下来，包括了用法和拓展的说明。如果有错误的地方，还请指出，谢谢！！！</p>
<h3 id="简单介绍"><a href="#简单介绍" class="headerlink" title="简单介绍"></a>简单介绍</h3><ol>
<li><p> Git 是分布式版本控制系统</p>
</li>
<li><p>执行提交时，系统会要求输入提交信息。</p>
<p><img src="https://cdn.jsdelivr.net/gh/AikikoXHJ/cloudimg/img/GitMdimg01.png"></p>
</li>
</ol>
<h3 id="创建一个本地仓库及基本操作"><a href="#创建一个本地仓库及基本操作" class="headerlink" title="创建一个本地仓库及基本操作"></a>创建一个本地仓库及基本操作</h3><ol>
<li><p>创建一个版本库</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">$ mkdir 库名 <span class="comment">#创建库</span></span><br><span class="line">$ <span class="built_in">cd</span> 库名 <span class="comment">#进入库</span></span><br><span class="line">$ <span class="built_in">pwd</span> <span class="comment">#打印出当前库的位置</span></span><br><span class="line">$ git init <span class="comment">#将这个目录变成Git可以管理的仓库</span></span><br><span class="line">$ ls -ah <span class="comment">#显示隐藏的.git目录线</span></span><br></pre></td></tr></table></figure></li>
<li><p>把文件添加到版本库</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">$ git add 文件名.后缀 <span class="comment">#将文件添加到仓库</span></span><br><span class="line">$ git commit -m <span class="string">&quot;提交的说明&quot;</span> <span class="comment">#将文件提交到仓库</span></span><br></pre></td></tr></table></figure></li>
<li><p>查看仓库状态</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">$ git status <span class="comment">#返回内容会告诉我们仓库的变化</span></span><br><span class="line">$ git diff 文件名 <span class="comment">#显示出文件变化的内容</span></span><br></pre></td></tr></table></figure></li>
<li><p>查看提交日志</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">$ git <span class="built_in">log</span> <span class="comment">#显示从近到远的提交日志</span></span><br><span class="line">$ git <span class="built_in">log</span> --pretty=oneline <span class="comment">#简化显示内容</span></span><br></pre></td></tr></table></figure></li>
<li><p>版本回退</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">$ git reset --hard HEAD^ <span class="comment">#回退到上个版本</span></span><br><span class="line"><span class="comment">#HEAD^代表上个版本，HEAD^^代表上上版本</span></span><br><span class="line"><span class="comment">#HEAD~100代表往上100个版本</span></span><br><span class="line">$ git reset --hard <span class="comment">#版本号前几位(至少5位)</span></span><br><span class="line">$ git reflog <span class="comment">#打印记录的每一次命令</span></span><br></pre></td></tr></table></figure></li>
<li><p>撤销修改</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#git add 之前的处理方式</span></span><br><span class="line">$ git checkout -- 文件名 <span class="comment">#将文件在工作区的修改全部撤销</span></span><br><span class="line"><span class="comment">#git add 之后的处理方式</span></span><br><span class="line">$ git reset HEAD 文件名 <span class="comment">#将暂存区的修改撤销</span></span><br><span class="line">$ git checkout -- 文件名</span><br><span class="line"><span class="comment"># git commit -m 之后，直接回退版本</span></span><br></pre></td></tr></table></figure></li>
<li><p>删除文件</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">$ rm 文件名 <span class="comment">#删除文件管理器中的文件</span></span><br><span class="line">$ git rm 文件名 <span class="comment">#删除版本库中的文件</span></span><br><span class="line">$ git commit -m 文件名 <span class="comment">#删除后提交一下</span></span><br><span class="line"><span class="comment">#如果删错了</span></span><br><span class="line">$ git checkout -- 文件名 <span class="comment">#用版本库里的文件替换工作区的</span></span><br></pre></td></tr></table></figure>
<h3 id="GitHub远程仓库操作"><a href="#GitHub远程仓库操作" class="headerlink" title="GitHub远程仓库操作"></a>GitHub远程仓库操作</h3></li>
<li><p>为GitHub创建SSH Key</p>
 <figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">$ ssh-keygen -t rsa -C <span class="string">&quot;邮箱&quot;</span></span><br><span class="line"><span class="comment">#.ssh目录里，id_rsa是私钥，id_rsa.pub是公钥</span></span><br></pre></td></tr></table></figure></li>
<li><p>本地仓库连接GitHub仓库</p>
 <figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">$ git remote add origin git@github.com:github账户名/仓库名.git</span><br><span class="line"><span class="comment">#origin 是远程仓库名，是默认的，可以改成其他的#通过不同的远程库名，可以让本地仓库连接多个远程库</span></span><br></pre></td></tr></table></figure></li>
<li><p>推送到远程仓库</p>
 <figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">$ git push -u origin master） <span class="comment">#将当前分支master推送到远程</span></span><br><span class="line"><span class="comment">#由于远程库是空的，第一次推送master分支时，加上了-u参数，Git</span></span><br><span class="line"><span class="comment">#不但会把本地的master分支内容推送到远程新的master分支</span></span><br><span class="line"><span class="comment">#还会把本地的master分支和远程的master分支关联起来</span></span><br><span class="line"><span class="comment">#在以后的推送或拉取时就可以简化命令$git push origin master </span></span><br><span class="line"><span class="comment">#将本地master分支的最新修改推送</span></span><br></pre></td></tr></table></figure></li>
<li><p>删除远程库</p>
 <figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">$ git remote -v <span class="comment">#查看远程库信息$ git remote rm origin </span></span><br><span class="line"><span class="comment">#根据名字删除，origin为默认远程库名</span></span><br><span class="line"><span class="comment">#这里的“删除”其实是接触本地与远程的绑定关系</span></span><br><span class="line"><span class="comment">#只有去GitHub上在后台页面找到删除按钮才能真正删除</span></span><br></pre></td></tr></table></figure>
<h3 id="克隆本地及分支操作"><a href="#克隆本地及分支操作" class="headerlink" title="克隆本地及分支操作"></a>克隆本地及分支操作</h3></li>
<li><p>从远程克隆一个本地库</p>
 <figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">$ git <span class="built_in">clone</span> git@github.com:GitHub账户名/仓库名.git <span class="comment">#普通克隆</span></span><br><span class="line">$ git <span class="built_in">clone</span> -b 分支名 git@github.com:GitHub账户名/仓库名.git <span class="comment">#克隆指定分支</span></span><br></pre></td></tr></table></figure></li>
<li><p>创建分支</p>
 <figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">$ git checkout -b 分支名 <span class="comment">#创建分支</span></span><br><span class="line"><span class="comment">#上面一条命令等于下面两条</span></span><br><span class="line">$ git branch 分支名</span><br><span class="line">$ git checkout 分支名</span><br></pre></td></tr></table></figure></li>
<li><p>查看当前分支</p>
 <figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">$ git branch <span class="comment">#查看当前所有分支</span></span><br><span class="line"><span class="comment">#列出来的分支中，当前分支前面会有一个 * 号</span></span><br></pre></td></tr></table></figure></li>
<li><p>切换分支</p>
 <figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">$ git checkout 分支名 <span class="comment">#切换分支</span></span><br><span class="line"><span class="comment">#更加科学，防止搞混的切换方法如下</span></span><br><span class="line">$ git switch -c 分支名 <span class="comment">#创建并切换到新的分支</span></span><br><span class="line">$ git switch 分支名 <span class="comment">#切换到已有的分支</span></span><br></pre></td></tr></table></figure></li>
<li><p>合并分支</p>
 <figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ git merge 分支名 <span class="comment">#将分支合并到当前分支</span></span><br></pre></td></tr></table></figure></li>
<li><p>删除分支</p>
 <figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ git branch -d 分支名 <span class="comment">#删除分支</span></span><br></pre></td></tr></table></figure></li>
<li><p>解决合并冲突</p>
 <figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#解决冲突需要我们手动编辑后重新提交</span></span><br><span class="line">$ git <span class="built_in">log</span> --graph --pretty=oneline --abbrev-commit <span class="comment">#打印分支合并图</span></span><br></pre></td></tr></table></figure></li>
<li><p>禁用 Fast forward 模式合并分支</p>
 <figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">$ git merge --no-ff -m <span class="string">&quot;提交消息&quot;</span> 分支名 <span class="comment">#禁用快速合并模式合并分支</span></span><br><span class="line"><span class="comment">#普通合并可以看出曾经做过合并，快速模式则不行</span></span><br></pre></td></tr></table></figure></li>
<li><p>“存储”当前分支（临时切换分支）</p>
 <figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">$ git stash <span class="comment">#将当前分支“存储”起来，以后恢复可继续工作</span></span><br><span class="line">$ git stash list <span class="comment">#查看“存储”起来的工作现场</span></span><br><span class="line"><span class="comment">#恢复方法一：恢复后，stash内容不会删除，需要单独删除</span></span><br><span class="line">$ git stash apply <span class="comment">#恢复</span></span><br><span class="line">$ git stash drop <span class="comment">#删除</span></span><br><span class="line"><span class="comment">#恢复方法二：恢复的同时删除stash的内容</span></span><br><span class="line">$ git stash pop<span class="comment">#多次stash后，选择性恢复</span></span><br><span class="line">$ git stash apply stash@&#123;0&#125; <span class="comment">#最后这里是需要恢复的编号</span></span><br></pre></td></tr></table></figure></li>
<li><p>复制一个特定的提交到当前分支</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ git cherry-pick 提交编号 <span class="comment">#将该编号的提交复制到当前分支上</span></span><br></pre></td></tr></table></figure></li>
<li><p>丢弃没有被合并过的分支</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ git branch -D 分支名 <span class="comment">#强行删除未合并的分支</span></span><br></pre></td></tr></table></figure></li>
<li><p>查看远程仓库的信息</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">$ git remote <span class="comment">#查看所有的远程仓库</span></span><br><span class="line">$ git remote -v <span class="comment">#查看所有远程仓库更为详细的信息</span></span><br></pre></td></tr></table></figure></li>
<li><p>推送分支</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#将该分支上的所有本地提交推送到远程库</span></span><br><span class="line"><span class="comment">#推送时需要指定本地分支</span></span><br><span class="line">$ git push origin 分支名</span><br></pre></td></tr></table></figure></li>
<li><p>抓取分支</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">$ git checkout -b 分支名 origin/分支名 <span class="comment">#创建远程origin的分支到本地</span></span><br><span class="line">$ git push origin 分支名 <span class="comment">#推送到分支#推送发生冲突的时候</span></span><br><span class="line">$ git branch --set-upstream-to=origin/分支名 分支名 <span class="comment">#连接本体与远程</span></span><br><span class="line">$ git pull <span class="comment">#将最新的提交从分支中抓取下来</span></span><br></pre></td></tr></table></figure></li>
<li><p>整理分支提交历史</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ git rebase <span class="comment">#将一大推分支图合成一条直线</span></span><br></pre></td></tr></table></figure>
<h3 id="标签基本操作"><a href="#标签基本操作" class="headerlink" title="标签基本操作"></a>标签基本操作</h3></li>
<li><p>创建标签</p>
 <figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">$ git branch <span class="comment">#打印所有分支</span></span><br><span class="line">$ git checkout 分支名 <span class="comment">#切换到需要打标签的分支上</span></span><br><span class="line">$ git tag 标签 <span class="comment">#打上标签</span></span><br><span class="line">$ git tag <span class="comment">#查看所有标签</span></span><br><span class="line">$ git tag 标签 提交的编号 <span class="comment">#给指定的提交打标签</span></span><br><span class="line">$ git show 标签 <span class="comment">#打印出标签的信息</span></span><br><span class="line">$ git tag -a 标签 -m <span class="string">&quot;说明文字&quot;</span> 提交的编号 <span class="comment">#创建带有说明的标签</span></span><br><span class="line"><span class="comment">#标签与某个commit(提交)挂钩的，如果这个commit(提交)出现在多个分支上</span></span><br><span class="line"><span class="comment">#那么这些分支上都可以看到这个标签</span></span><br></pre></td></tr></table></figure></li>
<li><p>操作标签</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">$ git tag -d 标签 <span class="comment">#删除标签</span></span><br><span class="line">$ git push origin 标签 <span class="comment">#推送某个标签到远程</span></span><br><span class="line">$ git push origin --tags <span class="comment">#一次性推送全部尚未推送到远程的本地标签</span></span><br><span class="line"><span class="comment">#删除远程标签</span></span><br><span class="line">$ git tag -d 标签 <span class="comment">#删除本地标签</span></span><br><span class="line">$ git push origin :refs/tags/标签 <span class="comment">#删除远程标签</span></span><br></pre></td></tr></table></figure>
<h3 id="Git的修改操作"><a href="#Git的修改操作" class="headerlink" title="Git的修改操作"></a>Git的修改操作</h3></li>
<li><p>自定义Git</p>
 <figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ git config --global color.ui <span class="literal">true</span> <span class="comment">#使Git会适当地显示不同的颜色</span></span><br></pre></td></tr></table></figure></li>
<li><p>忽略特殊文件</p>
<ol>
<li><p>在Git工作区的根目录下创建一个特殊的 .gitignore 文件，然后把要忽略的文件填进去，Git就会自动忽略这些文件</p>
<p><img src="https://cdn.jsdelivr.net/gh/AikikoXHJ/cloudimg/img/GitMdimg02.png"></p>
</li>
</ol>
</li>
<li><p>强行添加文件到Git</p>
 <figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ git add -f 文件名 <span class="comment">#-f可以强制添加文件到Git中</span></span><br></pre></td></tr></table></figure></li>
<li><p>设置自动补全</p>
 <figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ git config --<span class="keyword">global</span> alias.st status <span class="comment">#告诉Git st表示status</span></span><br></pre></td></tr></table></figure>
<h3 id="附录：命令表"><a href="#附录：命令表" class="headerlink" title="附录：命令表"></a>附录：命令表</h3><p> <img src="https://cdn.jsdelivr.net/gh/AikikoXHJ/cloudimg/img/GitMdsheet.png"></p>
</li>
</ol>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="mailto:undefined">AikikoXHJ</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="http://example.com/2021/06/06/GitMarkdown/">http://example.com/2021/06/06/GitMarkdown/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="http://example.com" target="_blank">Aikikoの小窝</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/Git/">Git</a></div><div class="post_share"><div class="social-share" data-image="https://cdn.jsdelivr.net/gh/AikikoXHJ/cloudimg/img/background.jpg" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/social-share.js/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/social-share.js/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-full"><a href="/2021/06/16/PythonNotion/"><img class="prev-cover" src="https://cdn.jsdelivr.net/gh/AikikoXHJ/cloudimg/img/background.jpg" onerror="onerror=null;src='/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">Python 笔记</div></div></a></div></nav></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="card-info-avatar is-center"><img class="avatar-img" src="https://cdn.jsdelivr.net/gh/AikikoXHJ/cloudimg/img/XHJ.jpg" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/><div class="author-info__name">AikikoXHJ</div><div class="author-info__description"></div></div><div class="card-info-data"><div class="card-info-data-item is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">2</div></a></div><div class="card-info-data-item is-center"><a href="/tags/"><div class="headline">标签</div><div class="length-num">2</div></a></div></div><a class="button--animated" id="card-info-btn" target="_blank" rel="noopener" href="https://github.com/AikikoXHJ"><i class="fab fa-github"></i><span>Follow Me</span></a><div class="card-info-social-icons is-center"><a class="social-icon" href="https://github.com/AikikoXHJ" target="_blank" title="Github"><i class="fab fa-github"></i></a><a class="social-icon" href="mailto:AikikoXHJ@outlook.com" target="_blank" title="Email"><i class="fas fa-envelope"></i></a></div></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn card-announcement-animation"></i><span>公告</span></div><div class="announcement_content">傻傻的脑袋里有大大的梦想~</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E7%AE%80%E5%8D%95%E4%BB%8B%E7%BB%8D"><span class="toc-number">1.</span> <span class="toc-text">简单介绍</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%88%9B%E5%BB%BA%E4%B8%80%E4%B8%AA%E6%9C%AC%E5%9C%B0%E4%BB%93%E5%BA%93%E5%8F%8A%E5%9F%BA%E6%9C%AC%E6%93%8D%E4%BD%9C"><span class="toc-number">2.</span> <span class="toc-text">创建一个本地仓库及基本操作</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#GitHub%E8%BF%9C%E7%A8%8B%E4%BB%93%E5%BA%93%E6%93%8D%E4%BD%9C"><span class="toc-number">3.</span> <span class="toc-text">GitHub远程仓库操作</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%85%8B%E9%9A%86%E6%9C%AC%E5%9C%B0%E5%8F%8A%E5%88%86%E6%94%AF%E6%93%8D%E4%BD%9C"><span class="toc-number">4.</span> <span class="toc-text">克隆本地及分支操作</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%A0%87%E7%AD%BE%E5%9F%BA%E6%9C%AC%E6%93%8D%E4%BD%9C"><span class="toc-number">5.</span> <span class="toc-text">标签基本操作</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Git%E7%9A%84%E4%BF%AE%E6%94%B9%E6%93%8D%E4%BD%9C"><span class="toc-number">6.</span> <span class="toc-text">Git的修改操作</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E9%99%84%E5%BD%95%EF%BC%9A%E5%91%BD%E4%BB%A4%E8%A1%A8"><span class="toc-number">7.</span> <span class="toc-text">附录：命令表</span></a></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/2021/06/16/PythonNotion/" title="Python 笔记"><img src="https://cdn.jsdelivr.net/gh/AikikoXHJ/cloudimg/img/background.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Python 笔记"/></a><div class="content"><a class="title" href="/2021/06/16/PythonNotion/" title="Python 笔记">Python 笔记</a><time datetime="2021-06-16T06:57:52.000Z" title="发表于 2021-06-16 14:57:52">2021-06-16</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2021/06/06/GitMarkdown/" title="Git 笔记"><img src="https://cdn.jsdelivr.net/gh/AikikoXHJ/cloudimg/img/background.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Git 笔记"/></a><div class="content"><a class="title" href="/2021/06/06/GitMarkdown/" title="Git 笔记">Git 笔记</a><time datetime="2021-06-05T16:00:00.000Z" title="发表于 2021-06-06 00:00:00">2021-06-06</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2021 By AikikoXHJ</div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script>var preloader = {
  endLoading: () => {
    document.body.style.overflow = 'auto';
    document.getElementById('loading-box').classList.add("loaded")
  },
  initLoading: () => {
    document.body.style.overflow = '';
    document.getElementById('loading-box').classList.remove("loaded")

  }
}
window.addEventListener('load',preloader.endLoading())</script><div class="js-pjax"></div><script async src = "/js/FunnyTitle.js"></script><script id="click-heart" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/click-heart.min.js" async="async" mobile="true"></script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div></body></html>